package com.eop.managedBean;

import java.io.Serializable;
import java.util.Date;

import javax.faces.model.SelectItem;

import org.operamasks.faces.annotation.Accessible;
import org.operamasks.faces.annotation.Bind;
import org.operamasks.faces.annotation.SaveState;
import org.operamasks.faces.annotation.SelectItems;

import com.base.common.provider.CommonKeySelectItemProvider;
import com.base.commons.SpringBeanHolder;
import com.base.security.SecurityReplace;
import com.base.security.SecurityUserHolder;
import com.eop.entity.Event;
import com.eop.service.IEventService;

public class BaseEventBean implements Serializable {
	protected IEventService eventService = SpringBeanHolder
			.getBean("eventService");
	@Bind
	@Accessible
	@SaveState
	protected String id;
	protected Event event;

	@Bind(id = "eventName", attribute = "value")
	protected String eventName;
	@Bind(id = "eventAddress", attribute = "value")
	protected String eventAddress;
	@Accessible
	protected SelectItem[] eventStatus_items = CommonKeySelectItemProvider
			.getCommonKey("stageInfoState", false);
	@Bind(id = "eventStatus")
	@SelectItems(source = "#{this.eventStatus_items}")
	protected String eventStatus;
	@Accessible
	protected SelectItem[] eventLevel_items = CommonKeySelectItemProvider
			.getCommonKey("eventLevel", false);
	@Bind(id = "eventLevel")
	@SelectItems(source = "#{this.eventLevel_items}")
	protected String eventLevel;
	@Bind(id = "eventReportDate", attribute = "value")
	protected Date eventReportDate;
	@Bind(id = "eventHappenDate", attribute = "value")
	protected Date eventHappenDate;
	@Bind(id = "eventRemark", attribute = "value")
	protected String eventRemark;
	// 适用范围
	@Accessible
	protected SelectItem[] eventRangeB_items = CommonKeySelectItemProvider
			.getTopCommonKey("srRangeBigType", false);
	@Bind(id = "eventRangeB")
	@SelectItems(source = "#{this.eventRangeB_items}")
	protected String eventRangeB;
	@Accessible
	protected SelectItem[] eventRangeS_items = {};
	@Bind(id = "eventRangeS")
	@SelectItems(source = "#{this.eventRangeS_items}")
	protected String eventRangeS;

	// 创建者
	@Bind(id = "eventCreateUser", attribute = "value")
	protected String eventCreateUser = SecurityUserHolder.getCurrentUserId();
	@Bind(id = "eventCreateUserName", attribute = "value")
	protected String eventCreateUserName = SecurityUserHolder
			.getCurrentUserFullName();
	// 创建时间
	@Bind(id = "eventCreateDate", attribute = "value")
	protected Date eventCreateDate = new Date();

	protected void setEventProperty() {
		if (event == null)
			return;
		event.setId(id);
		event.setEventAddress(eventAddress);
		// event.setEventCode(eventCode);
		event.setEventCreateDate(eventCreateDate);
		event.setEventCreateUser(eventCreateUser);
		event.setEvent_DelFlag(false);
		event.setEventHappenDate(eventHappenDate);
		// event.setEventHistoryDate(eventHistoryDate);
		// event.setEventHistoryFlag(eventHistoryFlag);
		event.setEventLevel(eventLevel);
		event.setEventName(eventName);
		event.setEventRangeB(eventRangeB);
		event.setEventRangeS(eventRangeS);
		event.setEventRemark(eventRemark);
		event.setEventReportDate(eventReportDate);
		event.setEventStatus(eventStatus);
		// event.setEventUpdateDate(eventUpdateDate);
		// event.setEventUpdateUser(eventUpdateUser);
	}

	protected void getEventProperty(Event event) {
		id = event.getId();
		eventAddress = event.getEventAddress();
		eventHappenDate = event.getEventHappenDate();
		eventLevel = event.getEventLevel();
		eventName = event.getEventName();
		eventRemark = event.getEventRemark();
		eventReportDate = event.getEventReportDate();
		eventStatus = event.getEventStatus();
		eventRangeB = event.getEventRangeB();
		eventRangeS = event.getEventRangeS();
		eventCreateUser = event.getEventCreateUser();
		eventCreateUserName = SecurityReplace
				.replaceUserFullName(eventCreateUser);
		eventCreateDate = event.getEventCreateDate();

	}
}
